package com.example.piece.vm

import androidx.lifecycle.SavedStateHandle
import com.example.base.ext.LoadingView
import com.example.base.vm.BaseViewModel
import com.example.base.vm.OnSuccess
import com.example.piece.entity.AttentionEntity
import com.example.piece.entity.RecommendEntity
import com.example.piece.repository.HomeRepository

class HomeViewModel(savedStateHandle: SavedStateHandle): BaseViewModel<HomeRepository>(savedStateHandle){
    override fun createRepository(): HomeRepository = HomeRepository()

    /**
     * 1
     * 获取主页的推荐关注数据
     * 获取被推荐关注的用户
     * @see List<RecommendEntity>
     * @see RecommendEntity
     * **/
    fun recommend(loadingView: LoadingView, onSuccess: OnSuccess<List<RecommendEntity>>) = Launch(loadingView) {
        val result = repository.recommend()
        onSuccess(result)
    }

    /**
     * 2
     * 获取关注的用户发布的段子列表
     *  获取关注用户发布的段子信息
     * @param page 页数
     *
     * @see List<AttentionEntity>
     * @see AttentionEntity
     */
    fun attentionList(loadingView: LoadingView?,page: String, onSuccess: OnSuccess<List<AttentionEntity>>) =
        Launch(loadingView) {
            val result = repository.attentionList(page)
            onSuccess(result)
        }

    /**
     * 3
     * 搜索段子
     * @param keyword 搜索的关键字
     * @param page 页数
     *
     * @see  List<AttentionEntity>
     * @see AttentionEntity
     */
    fun jokesSearch(
        loadingView: LoadingView?, keyword: String,
        page: String, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.jokesSearch(keyword, page)
        onSuccess(result)
    }

    /**
     * 4
     * 获取主页的最新列表数据
     * 获取最新列表数据
     * @see List<AttentionEntity>
     * @see AttentionEntity
     */
    fun homeLatest(
        loadingView: LoadingView?, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.homeLatest()
        onSuccess(result)
    }

    /**
     * 5
     * 获取主页的纯图片列表数据
     * 获取纯图片数据
     * @seeList<AttentionEntity>
     * @see AttentionEntity
     */
    fun homePic(
        loadingView: LoadingView?, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.homePic()
        onSuccess(result)
    }

    /**
     * 6
     * 获取主页的推荐列表数据
     * 或者主页推荐数据
     * @see List<AttentionEntity>
     * @see AttentionEntity
     */
    fun homeRecommend(
        loadingView: LoadingView?, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.homeRecommend()
        onSuccess(result)
    }

    /**
     * 7
     * 获取主页的纯文列表数据
     * 获取纯文本信息
     * @see List<AttentionEntity>
     * @see AttentionEntity
     */
    fun homeText(
        loadingView: LoadingView?, onSuccess: OnSuccess<List<AttentionEntity>>
    ) = Launch(loadingView) {
        val result = repository.homeText()
        onSuccess(result)
    }

}